package com.lrkj.payfee.controller;

import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.payfee.domain.FavouredPolicy;
import com.lrkj.payfee.service.IFavouredPolicyService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 优惠政策Controller
 *
 * @author yajun_ren
 * @date 2021-08-14
 */
@RestController
@RequestMapping("/payfee/favouredPolicy")
public class FavouredPolicyController extends BaseController
{
    @Autowired
    private IFavouredPolicyService favouredPolicyService;

    /**
     * 查询优惠政策列表
     */
    @ApiOperation(value = "查询优惠政策列表", notes = "查询优惠政策列表")
    @GetMapping("/list")
    public TableDataInfo list(FavouredPolicy favouredPolicy)
    {
        startPage();
        List<FavouredPolicy> list = favouredPolicyService.selectFavouredPolicyList(favouredPolicy);
        return getDataTable(list);
    }

    /**
     * 导出优惠政策列表
     */
	@ApiOperation(value = "导出优惠政策列表", notes = "导出优惠政策列表")
    @PreAuthorize("@ss.hasPermi('payfee:favouredPolicy:export')")
    @Log(title = "优惠政策", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FavouredPolicy favouredPolicy)
    {
        List<FavouredPolicy> list = favouredPolicyService.selectFavouredPolicyList(favouredPolicy);
        ExcelUtil<FavouredPolicy> util = new ExcelUtil<FavouredPolicy>(FavouredPolicy.class);
        return util.exportExcel(list, "优惠政策数据");
    }

    /**
     * 获取优惠政策详细信息
     */
	@ApiOperation(value = "获取优惠政策详细信息", notes = "获取优惠政策详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:favouredPolicy:query')")
    @GetMapping(value = "/{favouredPolicyId}")
    public AjaxResult getInfo(@PathVariable("favouredPolicyId") String favouredPolicyId)
    {
        return AjaxResult.success(favouredPolicyService.selectFavouredPolicyById(favouredPolicyId));
    }

    /**
     * 新增优惠政策
     */
	  @ApiOperation(value = "新增优惠政策", notes = "新增优惠政策")
    @PreAuthorize("@ss.hasPermi('payfee:favouredPolicy:add')")
    @Log(title = "优惠政策", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FavouredPolicy favouredPolicy)
    {
        return toAjax(favouredPolicyService.insertFavouredPolicy(favouredPolicy));
    }

    /**
     * 修改优惠政策
     */
	 @ApiOperation(value = "修改优惠政策", notes = "修改优惠政策")
    @PreAuthorize("@ss.hasPermi('payfee:favouredPolicy:edit')")
    @Log(title = "优惠政策", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FavouredPolicy favouredPolicy)
    {
        return toAjax(favouredPolicyService.updateFavouredPolicy(favouredPolicy));
    }

    /**
     * 删除优惠政策
     */
	 @ApiOperation(value = "删除优惠政策", notes = "删除优惠政策")
    @PreAuthorize("@ss.hasPermi('payfee:favouredPolicy:remove')")
    @Log(title = "优惠政策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{favouredPolicyIds}")
    public AjaxResult remove(@PathVariable String[] favouredPolicyIds)
    {
        return toAjax(favouredPolicyService.deleteFavouredPolicyByIds(favouredPolicyIds));
    }

    /**
     * 更新优惠政策状态
     */
    @ApiOperation(value = "更新优惠政策状态", notes = "更新优惠政策状态")
    @Log(title = "更新优惠政策状态", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody FavouredPolicy favouredPolicy)
    {
        return toAjax(favouredPolicyService.updateStatus(favouredPolicy));
    }
}
